print(rnorm(n=10))
#均值100 标准差20
print(rnorm(n=10,mean = 100,sd=20))
randNorm10 <- rnorm(10)
print(randNorm10)
print(dnorm(randNorm10))
print(dnorm(c(-1,0,1)))
randNorm <- rnorm(30000)
randDesity <- dnorm(randNorm)
library(ggplot2)
ggplot(data.frame(x=randNorm,y=randDesity))+aes(x=x,y=y)+geom_point() +labs(x="Random Normal Variables",y="Density")
print(pnorm(randNorm10))
print(pnorm(c(-3,0,3)))
print(pnorm(-1))
print(pnorm(1) - pnorm(0))
print(pnorm(1)-pnorm(-1))
# 小于-1的概率密度图
p <- ggplot(data.frame(x=randNorm,y=randDesity)) + aes(x=x,y=y) + geom_line() + labs(x="x",y="Density")
neg1seq <- seq(from=min(randNorm),to=-1,by=.1)
lessThanNeg1 <- data.frame(x=neg1seq,y=dnorm(neg1seq))
lessThanNeg1 <- rbind(c(min(randNorm),0),lessThanNeg1,c(max(lessThanNeg1$x),0))
print(lessThanNeg1)
pp <- p + geom_polygon(data=lessThanNeg1,aes(x=x,y=y))
print(pp)
# 大于-1和小于1 的概率密度图
neglPos1Seq <- seq(from=-1,to=1,by=.1)
neg1Tol <- data.frame(x=neglPos1Seq,y=dnorm(neglPos1Seq))
print(head(neg1Tol))
neg1Tol <- rbind(c(min(neg1Tol$x),0),neg1Tol,c(max(neg1Tol$x),0))
pp <- p + geom_polygon(data = neg1Tol,aes(x=x,y=y))
print(pp)
randProb = pnorm(randNorm)
print(ggplot(data.frame(x=randNorm,y=randProb)) + aes(x=x,y=y) + geom_point() + labs(x="Random Normal Variables", y="Probability"))

